<?php

declare(strict_types=1);
namespace App\Service\AppService;
/**
 * @author chenshubo
 * 重写 Meta 生成器 
 */

use Hyperf\Snowflake\IdGenerator;

class SnowFlakeService
{
    /**
     * @var IdGenerator\SnowflakeIdGenerator
     */
    protected $idGenerator;
    public function __construct(IdGenerator\SnowflakeIdGenerator $idGenerator)
    {
        $this->idGenerator = $idGenerator;
    }
    
    public function generate()
    {
        $beginTimesStamp = (int)(config('snowflake.begin_date').'000');
        $meta = $this->idGenerator->getMetaGenerator()->generate();
        $meta->setBeginTimesTamp($beginTimesStamp);
        return (string)$this->idGenerator->generate($meta);
    }
    
    public function degenerate(int $id)
    {
        return $this->idGenerator->degenerate($id);
    }
}